from moviepy import VideoFileClip
from .responses import Response
# 将视频转换成音频，可从mp4转换成wav
def extract_audio_from_video(video_path, audio_output_path):
    try:
        # 加载视频文件
        video = VideoFileClip(video_path)

        # 提取音频
        audio = video.audio

        # 保存音频文件
        audio.write_audiofile(audio_output_path)

        # 关闭视频对象
        video.close()
        return Response(status=True, messages="")
    except Exception as e:
        return Response(status=False, messages=str(e))

if __name__ == '__main__':
    # 示例：将视频文件 'example.mp4' 的音频提取并保存为 'output_audio.mp3'
    extract_audio_from_video('../origin_video/clipping_video.mp4', 'fakao_test.wav')